package bsc.war.ajax;

import bsc.ejb.entity.ActionPlan;
import bsc.ejb.entity.Person;
import bsc.ejb.entity.ScoreDomain;
import bsc.ejb.metadata.Colorimetry;
import bsc.ejb.metadata.Framework;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import bsc.war.model.ActionPlanPojo;
import bsc.war.service.ScoreCardUtils;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author Miguel Angel
 */
public class ModifyActionPlan extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        try {

            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");

            Long idActionPlan = Long.parseLong(request.getParameter("actionPlan"));
            ActionPlan actionPlan = delegate.findActionPlan(idActionPlan);
            ActionPlanPojo actionPlanPojo = ScoreCardUtils.getActionPlan(delegate, actionPlan);

            String scoreCard = request.getParameter("scoreCard");


            ScoreDomain currentSD = (ScoreDomain) request.getSession().getAttribute("currentScoreDomain");
            Framework framework = (Framework) request.getSession().getAttribute("framework");

            List<Colorimetry> colorimetries = delegate.findColorimetry(framework, Boolean.TRUE);
            List<Person> persons = delegate.findPerson(currentSD);

            
            ActionPlan.Status statuses[]= ActionPlan.Status.values();

            request.setAttribute("actionPlanPojo", actionPlanPojo);
            request.setAttribute("scoreCard", scoreCard);
            request.setAttribute("colorimetries", colorimetries);
            request.setAttribute("persons", persons);
            request.setAttribute("statuses", statuses);

        } catch (Exception e) {
            e.printStackTrace();
        }

        return new ModelAndView("modifyActionPlan");
    }
}
